//
//  HomePageViewController.m
//  WG
//
//  Created by 万国地球村 on 16/5/27.
//  Copyright © 2016年 万国地球村. All rights reserved.
//

#import "HomePageViewController.h"
#import "CWCarousel.h"
#import "YQBannerView.h"
#import "YQLoginViewController.h"
#import "YQOverseasBuyersCtlViewController.h"
#import "YQFourTypeBtnView.h"
#import "YQConsultantView.h"
#import "YQBigVisaCtl.h"

#define KWIDTH [UIScreen mainScreen].bounds.size.width
#define KHEIGHT [UIScreen mainScreen].bounds.size.height
#define KSpace 20


@interface HomePageViewController ()

@property (nonatomic, strong) UITextField *searchTF;
@property (nonatomic, strong) YQBannerView *bannerView;


@end

@implementation HomePageViewController

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.bannerView.carousel controllerWillDisAppear];
    [self.tabBarController.tabBar setHidden:NO];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.bannerView.carousel controllerWillAppear];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad {
    
    self.view.backgroundColor = WhiteColor;
    UIView *navigationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH, 64)];
    navigationView.backgroundColor = UIColorFromRGB(0x715142);
    [self.view addSubview:navigationView];
    CGFloat navi_H = navigationView.frame.size.height;
    
    UILabel *shouyeLabel = [[UILabel alloc] initWithFrame:CGRectMake(KWIDTH/3.0, navi_H/4.0+5, KWIDTH/3.0, navi_H/2.0)];
    shouyeLabel.text = @"侨外移民";
    shouyeLabel.textColor = [UIColor whiteColor];
    shouyeLabel.adjustsFontSizeToFitWidth = YES;
    shouyeLabel.textAlignment = NSTextAlignmentCenter;
    [navigationView addSubview:shouyeLabel];
    
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [loginBtn setTitle:@"登陆" forState:UIControlStateNormal];
    loginBtn.titleLabel.textColor = [UIColor whiteColor];
    loginBtn.frame = CGRectMake(2*KWIDTH/3.0, navi_H/4.0+5, KWIDTH/3.0-10, navi_H/2.0);
    loginBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    loginBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
    loginBtn.titleLabel.adjustsFontSizeToFitWidth = YES;
    [loginBtn addTarget:self action:@selector(loginAction:) forControlEvents:UIControlEventTouchUpInside];
    [navigationView addSubview:loginBtn];
    
    self.bannerView = [[YQBannerView alloc] initWithFrame:CGRectMake(0, kNavigationBarHeight+10, CGRectGetWidth(self.view.frame), FIT(230))];
    [self.view addSubview:self.bannerView];
    
    //设置下面4个button
    [self setupFourTypeBtn];
    
}
//登陆
-(void)loginAction:(UIButton *)sender
{
    [self presentViewController:[YQLoginViewController new] animated:YES completion:nil];
}

- (void)setupFourTypeBtn {
    YQFourTypeBtnView *btnView = [[YQFourTypeBtnView alloc] init];
    [self.view addSubview:btnView];
    [btnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.equalTo(self.bannerView.mas_bottom).mas_equalTo(FIT(20));
        make.size.mas_equalTo(CGSizeMake(SCREENWIDTH, FIT(100)));
    }];
    btnView.block = ^(NSInteger index) {
        if (index == 1) {
            YQ_PUSH([YQOverseasBuyersCtlViewController new]);
        }else if (index == 2) {
            
        }else if (index == 3) {
            //大国签证
            YQ_PUSH([YQBigVisaCtl new]);
        }else {
            //
        }
    };
    
    YQConsultantView *consultantView = [[YQConsultantView alloc] init];
    [self.view addSubview:consultantView];
    [consultantView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(btnView.mas_bottom).mas_equalTo(20);
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(SCREENWIDTH);
        make.height.mas_equalTo(SCREENHEIGHT-kNavigationBarHeight-10-FIT(230)-FIT(120));
    }];
    
}

@end
